﻿using System;
using System.Data;
using System.Web.UI;
using BLL;

public partial class Top : System.Web.UI.Page
{
    public string companyName = System.Configuration.ConfigurationManager.AppSettings["CompanyName"].ToString();
    public string welcome = "";
    Authentication dllAuthentication = new Authentication();
    UserInfoManager dllUserInfoManager = new UserInfoManager();
    public string Openpage = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        Model.UserInfo objUserInfo = new Model.UserInfo();

        #region 用于单点登录访问OA
        //构建本地时间转化秒值，用于对比
        DateTime localdate = DateTime.Now;
        int hour = (localdate.Hour * 3600);
        int mm = (localdate.Minute * 60);
        //拼成目标时间值，并转为double型，用于比对。
        int localtime = hour + mm + localdate.Second;
        string sql = "select * from DS_UserInfo where UserName='" + objUserInfo.UserName + "'";
        DataTable dt = DAL.SqlHelper.ExecuteDataset(DAL.SqlHelper.connStr, CommandType.Text, sql).Tables[0];
        if (dt.Rows.Count > 0)
        {
            Openpage = "Username=" + dt.Rows[0]["ItCode"].ToString() + "&Password=" + dt.Rows[0]["UserPassWord"].ToString() + "&loginTime=" + localtime + "";
        }
        if (Openpage.Length > 0)
        {
            //Openpage = OACommon.OAEncrypt.Encrypt(Openpage);
        }
        #endregion
        dllAuthentication.isLogin();
        //Model.UserInfo objUserInfo = new Model.UserInfo();
        object[] _value = new object[1];
        _value[0] = objUserInfo.UserName;
        DataTable _userTable = dllUserInfoManager.get(UserInfoManager.field.UserName.ToString(), _value);
        if (_userTable.Rows.Count > 0)
        {
            string _welCome = _userTable.Rows[0]["RealName"].ToString();
            _welCome = _welCome + " 您好！今天是" + DateTime.Now.ToLongDateString() + " " + ConvertDayOfWeekToZh(DateTime.Now.DayOfWeek);
            welcome = _welCome;
        }
    }

    public string urlload()
    {
        string str = "";
        str += "<table id='menuLists' style='display: none; border-color: Black; border-style: solid;";
        str += " border-collapse: collapse; width: 126px;' border='1' cellpadding='0' cellspacing='0'>";
        str += " <tr>";
        str += "<td style='height: 1px'>";
        str += " </td>";
        str += " </tr>";


        //循环显示内容

        DataSet dsRule = new DataSet();
        dsRule.ReadXml(Getpath());

        DataTable dtRule = dsRule.Tables[0];
        foreach (DataRow dr in dtRule.Rows)
        {
            str += "<tr style='background-color: #DEDBDE'>";
            str += "  <td style='height: 25px' onmouseover=\"this.className='display'\" onmouseout=\"this.className='none'\">";
            str += "<a href='" + dr["地址"].ToString() + "' target='_bland' onclick=\"popMenu('menuLists');\"><span style='padding-left: 3px'>" + dr["标题"].ToString() + "</span></a></td>";
            str += "</tr>";
        }
        str += "</table>";

        return str;
    }

    string Getpath()
    {
        string xmlPath = "admin\\config\\config.xml";
        string s = Server.MapPath("~/");
        xmlPath = s + xmlPath;
        return xmlPath;
    }
    public static string ConvertDayOfWeekToZh(System.DayOfWeek dw)
    {
        string DayOfWeekZh = "";
        switch (dw.ToString("D"))
        {
            case "0":
                DayOfWeekZh = "星期日";
                break;
            case "1":
                DayOfWeekZh = "星期一";
                break;
            case "2":
                DayOfWeekZh = "星期二";
                break;
            case "3":
                DayOfWeekZh = "星期三";
                break;
            case "4":
                DayOfWeekZh = "星期四";
                break;
            case "5":
                DayOfWeekZh = "星期五";
                break;
            case "6":
                DayOfWeekZh = "星期六";
                break;
        }
        return DayOfWeekZh;
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Write("<script>closes.Click();</script>");

    }
}
